package com.hq.shcrm.controller;

import com.hq.shcrm.pojo.CurdResult;
import com.hq.shcrm.pojo.PageResult;
import com.hq.shcrm.pojo.TCourseOrder;
import com.hq.shcrm.service.ICourceOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/courseorder")
public class CourseorderController {

    @Autowired
    ICourceOrderService iCourceOrderService;

    @RequestMapping("/list")
    public String list(){
        return "courseorder.html";
    }

    @RequestMapping("/add")
    public String add(){
        return "addcourseorder.html";
    }

    @RequestMapping("/update")
    @ResponseBody
    public CurdResult update(TCourseOrder order){
        CurdResult result = new CurdResult();
        iCourceOrderService.update(order);
        return result;
    }

    @RequestMapping("/edit")
    public String edit(Model model,String order_id){
        TCourseOrder courseOrder = iCourceOrderService.findbyOrderId(order_id);
        model.addAttribute("courseOrder", courseOrder);
        return "edit.html";
    }

    @RequestMapping("/detail")
    public String detail(Model model,String order_id){
        TCourseOrder courseOrder = iCourceOrderService.findbyOrderId(order_id);
        model.addAttribute("courseOrder", courseOrder);
        return "detail.html";
    }

    @RequestMapping("/save")
    @ResponseBody
    public CurdResult save(TCourseOrder order){
        CurdResult result = new CurdResult();
        System.out.println(order);
        iCourceOrderService.save(order);
        return result;
    }

    @RequestMapping("/delete")
    @ResponseBody
    public CurdResult delete(String order_id){
        CurdResult result = new CurdResult();
        iCourceOrderService.deletebyOrderId(order_id);
        return result;
    }
    @RequestMapping("/listJson")
    @ResponseBody
    public PageResult<TCourseOrder> listJson(TCourseOrder condition,int page,int limit){
        return iCourceOrderService.findPageResult(condition,page,limit);
    }
}
